Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add distribution module examples #208

Merged
merged 3 commits into from
Mar 5, 2024

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Mar 5, 2024

  • Added required logic to support messages and queries provided by the chain distribution module.
  • Added example scripts for the new functionality

Summary by CodeRabbit

  • New Features
    • Expanded ChainClient interface to include distribution module methods for blockchain interactions.
    • Added examples demonstrating how to interact with blockchain networks for various distribution-related activities using the InjectiveLabs SDK. Activities include setting withdrawal addresses, withdrawing validator commissions, funding the community pool, and querying various distribution information such as validator info, rewards, commissions, slashes, and community pool balance.

@aarmoa aarmoa requested a review from nicolasbaum March 5, 2024 17:47
Copy link

coderabbitai bot commented Mar 5, 2024

Walkthrough

The recent update brings significant enhancements to the ChainClient interface, expanding it to include methods for the distribution module. This update enables interactions with various distribution-related information within blockchain networks, such as validator distribution, rewards, commissions, slashes, and community pool details. Practical examples demonstrate setting withdrawal addresses, withdrawing validator commissions, funding the community pool, and querying distribution-related information.

Changes

Files Change Summary
client/chain/chain.go, client/chain/chain_test_support.go Expanded ChainClient interface to include distribution module methods. Added distributionQueryClient field.
examples/chain/distribution/1_SetWithdrawAddress/example.go Introduces setting withdrawal addresses for delegators using the Injective Labs SDK.
examples/chain/distribution/3_WithdrawValidatorCommission/example.go Presents a program to withdraw validator commission in a blockchain network using the InjectiveLabs SDK.
examples/chain/distribution/4_FundCommunityPool/example.go Adds functionality to fund the community pool in a blockchain network using the InjectiveLabs SDK.
examples/chain/distribution/query/4_ValidatorSlashes/example.go Introduces a program to fetch validator slash information in a blockchain network using the InjectiveLabs SDK.

"In the realm of code, where logic intertwines,
A rabbit hopped in, with changes so fine.
🌟 From yaml to chain, it leaped with ease,
Unveiling treasures, for developers to seize.
🚀 To the cosmos and beyond, it whispered in the night,
'Let your code flourish, in the blockchain's light.'"


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 1.51515% with 65 lines in your changes are missing coverage. Please review.

Project coverage is 29.01%. Comparing base (bd9ffbe) to head (d64bc93).

Files Patch % Lines
client/chain/chain.go 2.08% 47 Missing ⚠️
client/chain/chain_test_support.go 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #208      +/-   ##
==========================================
- Coverage   29.71%   29.01%   -0.71%     
==========================================
  Files          17       17              
  Lines        2564     2630      +66     
==========================================
+ Hits          762      763       +1     
- Misses       1766     1831      +65     
  Partials       36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 19

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between bd9ffbe and 1141d09.
Files selected for processing (15)
  • .coderabbit.yaml (1 hunks)
  • client/chain/chain.go (5 hunks)
  • client/chain/chain_test_support.go (2 hunks)
  • examples/chain/distribution/1_SetWithdrawAddress/example.go (1 hunks)
  • examples/chain/distribution/3_WithdrawValidatorCommission/example.go (1 hunks)
  • examples/chain/distribution/4_FundCommunityPool/example.go (1 hunks)
  • examples/chain/distribution/query/1_ValidatorDistributionInfo/example.go (1 hunks)
  • examples/chain/distribution/query/2_ValidatorOutstandingRewards/example.go (1 hunks)
  • examples/chain/distribution/query/3_ValidatorCommission/example.go (1 hunks)
  • examples/chain/distribution/query/4_ValidatorSlashes/example.go (1 hunks)
  • examples/chain/distribution/query/5_DelegationRewards/example.go (1 hunks)
  • examples/chain/distribution/query/6_DelegationTotalRewards/example.go (1 hunks)
  • examples/chain/distribution/query/7_DelegatorValidators/example.go (1 hunks)
  • examples/chain/distribution/query/8_DelegatorWithdrawAddress/example.go (1 hunks)
  • examples/chain/distribution/query/9_CommunityPool/example.go (1 hunks)
Additional comments: 5
.coderabbit.yaml (1)
  • 1-8: The automation configuration in .coderabbit.yaml looks good and aligns with standard development workflows. It's a great addition for streamlining the review and chat reply process based on the specified base branches.
client/chain/chain.go (4)
  • 171-180: The addition of methods related to the distribution module in the ChainClient interface is correctly implemented. These methods cover a wide range of functionalities necessary for interacting with the distribution aspects of a blockchain network, such as fetching validator distribution info, outstanding rewards, commissions, slashes, delegation rewards, total rewards, delegator validators, delegator withdraw address, and community pool details. This expansion aligns with the PR objectives and enhances the library's capabilities significantly.
  • 217-217: The inclusion of the distributionQueryClient field in the chainClient struct is a necessary addition to facilitate interactions with the distribution module. This change is well-implemented and follows the pattern established by other module-specific query clients in the struct. It ensures that the new distribution-related methods have the required client to make gRPC calls to the blockchain network.
  • 312-312: Initializing the distributionQueryClient within the NewChainClient function is correctly done. This step is crucial for setting up the client with the ability to interact with the distribution module right from the creation of a chainClient instance. The use of distributiontypes.NewQueryClient(conn) is consistent with how other module-specific clients are initialized, ensuring uniformity and maintainability.
  • 1513-1576: The implementation of the distribution module-related methods in the chainClient struct is thorough and covers all the functionalities outlined in the PR objectives. Each method correctly constructs the request object, makes the gRPC call using the distributionQueryClient, and returns the response. This comprehensive implementation enables users of the library to interact with various aspects of the distribution module, enhancing the library's utility for blockchain network interactions. It's also worth noting that the methods are implemented consistently with existing patterns in the codebase, which aids in maintainability.

Comment on lines 6 to 12
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"os"

"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider organizing imports by grouping standard library imports separately from third-party imports for better readability.

import (
	"encoding/json"
	"fmt"
	"os"
	
	"github.com/cosmos/cosmos-sdk/x/distribution/types"
	"github.com/InjectiveLabs/sdk-go/client"
	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
	"github.com/InjectiveLabs/sdk-go/client/common"
	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"os"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
import (
"encoding/json"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)

Comment on lines +22 to +30
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding sensitive information such as the mnemonic and keyring passphrase ("12345678") in the source code is a security risk. Consider using environment variables or secure vaults for sensitive data.

Comment on lines +66 to +70
response, err := chainClient.AsyncBroadcastMsg(msg)

if err != nil {
panic(err)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling for AsyncBroadcastMsg is done by panicking. While this might be acceptable for an example script, in production code, it's better to handle errors gracefully. Consider logging the error or returning it to the caller.

Comment on lines 6 to 13
"fmt"
"github.com/cosmos/cosmos-sdk/types/query"
"os"

"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous file, consider organizing imports by grouping standard library imports separately from third-party imports for better readability.

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	
	"github.com/cosmos/cosmos-sdk/types/query"
	"github.com/InjectiveLabs/sdk-go/client"
	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
	"github.com/InjectiveLabs/sdk-go/client/common"
	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"fmt"
"github.com/cosmos/cosmos-sdk/types/query"
"os"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)

Comment on lines +23 to +31
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same security concern applies here regarding the hardcoding of sensitive information. Use environment variables or secure vaults instead.

Comment on lines +16 to +70
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}

validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()

res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for querying validator commission follows the established pattern of initialization and querying. The handling of sensitive information, such as the private key, needs to be securely managed to adhere to security best practices.

- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}

Comment on lines +16 to +70
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}

validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()

res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example script for querying validator distribution info is consistent with the patterns observed in previous files. The recommendation regarding the secure handling of sensitive information, such as the private key, remains critically important.

- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}

Comment on lines +16 to +70
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}

validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()

res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for querying validator outstanding rewards follows the established pattern of initialization and querying. The handling of sensitive information, such as the private key, needs to be securely managed to adhere to security best practices.

- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z"
ctx := context.Background()
res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}

Comment on lines +16 to +71
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}

delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5"
ctx := context.Background()

res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress)
if err != nil {
fmt.Println(err)
}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example script for querying delegation rewards is consistent with the patterns observed in previous files. The recommendation regarding the secure handling of sensitive information, such as the private key, remains critically important.

- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5"
ctx := context.Background()
res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5"
ctx := context.Background()
res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
}

Comment on lines +16 to +73
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}

validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5"

msg := &types.MsgWithdrawValidatorCommission{
ValidatorAddress: validatorAddress,
}

//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
response, err := chainClient.AsyncBroadcastMsg(msg)

if err != nil {
panic(err)
}

str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for withdrawing validator commission is well-structured and demonstrates the transaction broadcast process effectively. As with previous scripts, ensure that sensitive information, such as the private key, is securely managed and not hardcoded.

- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5"
msg := &types.MsgWithdrawValidatorCommission{
ValidatorAddress: validatorAddress,
}
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
response, err := chainClient.AsyncBroadcastMsg(msg)
if err != nil {
panic(err)
}
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
}
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5"
msg := &types.MsgWithdrawValidatorCommission{
ValidatorAddress: validatorAddress,
}
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
response, err := chainClient.AsyncBroadcastMsg(msg)
if err != nil {
panic(err)
}
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 1141d09 and d64bc93.
Files selected for processing (6)
  • client/chain/chain.go (5 hunks)
  • client/chain/chain_test_support.go (2 hunks)
  • examples/chain/distribution/1_SetWithdrawAddress/example.go (1 hunks)
  • examples/chain/distribution/3_WithdrawValidatorCommission/example.go (1 hunks)
  • examples/chain/distribution/4_FundCommunityPool/example.go (1 hunks)
  • examples/chain/distribution/query/4_ValidatorSlashes/example.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • client/chain/chain.go
  • client/chain/chain_test_support.go
  • examples/chain/distribution/1_SetWithdrawAddress/example.go
  • examples/chain/distribution/3_WithdrawValidatorCommission/example.go
  • examples/chain/distribution/4_FundCommunityPool/example.go
  • examples/chain/distribution/query/4_ValidatorSlashes/example.go

@aarmoa aarmoa merged commit bb47a8f into dev Mar 5, 2024
2 of 4 checks passed
@aarmoa aarmoa deleted the feat/add_distribution_module_examples branch March 5, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants